﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.SystemManage
{
    public partial class CompanyCheckInfo : BasePage
    {
        public CompanyCheckInfo()
        {
            this.ModuleNo = Module.系统管理.ToString();
            this.PageOperateType = OperateType.企业管理.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
                //if (!CurrentAccount.GetUser().UserID.Substring(0, 1).Equals("A"))
                //{
                //    IBLL_Company ic = Factory.BLL_Company();
                //    int totalCount = 0 ;
                //    string comPS_Id = Request.QueryString["psid"].ToString();
                //    DataTable dt = ic.GetUnionCityCompanyInfoBySelect(comPS_Id, 1, 0, out totalCount);
                //    gvwCheckList.DataSource = dt;
                //    gvwCheckList.DataBind();
                //}
                if(CurrentAccount.GetUser().UserID.Substring(0,1).Equals("A"))
                {
                    btnPasss.Visible = false;
                    btnUnPasss.Visible = false;
                }
            }
        }
        public void BindData()
        {
            if (Request.QueryString["psid"] != "" && Request.QueryString["psid"] != null)
            {
                string comPS_Id = Request.QueryString["psid"].ToString();
                this.lblSort.Text = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyType(comPS_Id);
                HZ.DrugTrade.Model.CompanyInfo com = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().GetCompanyInfoByID(comPS_Id);
                this.lblAddress.Text = com.Address;//联系地址
                this.lbladulterant.Text = com.Adulterant;//两年内有无假药记录
                this.lblAuthor.Text = com.Author;//被授权人
                this.lblAuthorCell.Text = com.AuthorCell;//被授权人手机
                this.lblCellPhone.Text = com.CellNo;//联系人手机
                this.lblComCode.Text = com.Comcode;//企业代码证号
                this.lblComEndTime.Text = Constants.ReturnTime(com.ComEndtime);//企业代码证有效期
                this.lblComFax.Text = com.Fax;//企业传真
                this.lblComName.Text = com.CompanyName;//企业名称
                this.lblComTel.Text = com.TelNo;//企业联系电话
                this.lbldevious.Text = com.Devious;//是否有不正当行为
                this.lblEmail.Text = com.Email;//电子信箱
                this.lblPermission.Text = com.Permission;//营业执照号
                if (com.Permissionloogtime != 1)
                {
                    this.lblPermissionDate.Text = Constants.ReturnTime(com.PermissionDate);//营业执照期限
                }
                else
                {
                    this.lblPermissionDate.Text = "长期";
                }
                this.lblPermissionCheckDate.Text = Constants.ReturnTime(com.PermissionCheckDate);//营业执照年检日期
                this.lblPermitLicence.Text = com.BusinessCertificate;//生产或经营许可证号
                if (com.Businessloogtime != 1)
                {
                    this.lblPermitLicenceEndTime.Text = Constants.ReturnTime(com.BusinessCertificateDate);//许可证有效期
                }
                else
                {
                    this.lblPermitLicenceEndTime.Text = "长期";//许可证有效期
                }
                
                this.lblPermitLicenceRange.Text = com.BusinessRange;//经营范围
                this.lblPostCode.Text = com.PostCode;//邮政编码
                this.lblRegisterAddress.Text = com.RegistAddress;//企业注册地址
                this.lblRegisterFund.Text = com.RegisterFund.ToString();//企业注册资金
                this.lblStoreHouseAddress.Text = com.StoreHouseAddress;//仓库地址
                this.lblLawerPerson.Text = com.LayMan;//法人
                this.lblInstruments.Text = com.Instruments;//医疗器械许可证号
                this.lblContactPerson.Text = com.ContactPerson;//企业联系人
                this.lblRemarks.Text = com.Remarks;//备注
                this.lblUserCode.Text = comPS_Id;//企业用户编号
                this.txtOtherReason.Text = com.CheckReason;//审核原因
                if (com.CheckStatus==1)//若审核通过不绑定原因
                {
                    this.txtOtherReason.Text = "";
                }
                //if (CurrentAccount.GetUser().UserID.ToUpper().Contains("ZBZX"))
                //{
                //    txtOtherReason.Text = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select reasonByZbzx from TB_PSselectArea where companyPS_Id='" + comPS_Id + "'").ToString();
                //}
                //else
                //{
                //    txtOtherReason.Text = HZ.Data.DbHelperFactory.Create().ExecuteScalar("select reason from TB_PSselectArea where companyPS_Id='" + comPS_Id + "'").ToString();
                //}
            }
            else
            {
                this.Controls.Add(new LiteralControl("<script>alert('参数错误')</script>"));
                Response.Redirect("../UserLogin.aspx");
            }
        }

        //审核通过
        protected void btnPass_Click(object sender, EventArgs e)
        {
            string userId = CurrentAccount.GetUser().UserID;
            HZ.DrugTrade.Model.PSSelectArea ps = new HZ.DrugTrade.Model.PSSelectArea();
            ps.CompanyPS_Id = Request.QueryString["psid"].ToString();
            ps.Reason = txtOtherReason.Text;
            ps.AreaId = CurrentAccount.GetUser().Org.Area.AreaID;
            string state = "";
            if (CurrentAccount.GetUser().UserID.Substring(0,1).ToString() == "A")
            {
                state = "1";
            }
            bool flag = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().CheckCompanyInfo(ps, 1, userId, state);
            if (flag)
            {
                HZ.Web.MessageBox.Show("审核成功");
                BindData();
            }
            else
            {
                HZ.Web.MessageBox.Show("审核失败");
            }
        }
        //审核不通过
        protected void btnUnPass_Click(object sender, EventArgs e)
        {
            if (txtOtherReason.Text == "")
            {
                HZ.Web.MessageBox.Show("请填写不通过理由");
                return;
            }
            else
            {
                string userId = CurrentAccount.GetUser().UserID;
                HZ.DrugTrade.Model.PSSelectArea ps = new HZ.DrugTrade.Model.PSSelectArea();
                ps.CompanyPS_Id = Request.QueryString["psid"].ToString();
                ps.Reason = txtOtherReason.Text;
                ps.AreaId = CurrentAccount.GetUser().Org.Area.AreaID;
                string state = "";
                if (CurrentAccount.GetUser().UserID.Substring(0, 1).ToString() == "A")
                {
                    state = "1";
                }
                bool flag = HZ.DrugTrade.BLLFactory.Factory.BLL_Company().CheckCompanyInfo(ps, 2, userId,state);
                if (flag)
                {
                    HZ.Web.MessageBox.Show("审核成功");
                    BindData();
                }
                else
                {
                    HZ.Web.MessageBox.Show("审核失败");
                }
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("CompanyCheckedList.aspx");
        }
        protected string UnionCityCheckState(string str)
        {
            if (str == "1")
            {
                return "<label style='color:green;'>已通过</label>";
            }
            if (str == "2")
            {
                return "<label style='color:red;'>未通过</label>";
            }
            return "未审核";
        }
    }
}
